package com.zero.basic.dao;

import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

@Repository("uniqueQuerybaseDao")
public class HqlQueryBaseDao<T> extends DefaultBaseDao<T> {

	public Object queryObject(String hql, Object[] args) {
		return this.queryObject(hql, args, null);
	}

	public Object queryObject(String hql, Object arg) {
		return this.queryObject(hql, new Object[] { arg });
	}

	public Object queryObject(String hql) {
		return this.queryObject(hql, null);
	}

	public Object queryObject(String hql, Object[] args,
			Map<String, Object> alias) {
		Query query = getSession().createQuery(hql);
		setAliasParameter(query, alias);
		setParameter(query, args);
		return query.uniqueResult();
	}

	public Object queryObjectByAlias(String hql, Map<String, Object> alias) {
		return this.queryObject(hql, null, alias);
	}
}